package com.gorkr.labuladong.data_struct.bt;

import org.junit.jupiter.api.Test;

/**
 * @author gorkr
 * @date 2022/08/06 08:42
 **/
public class E28DuiChengDeErCHaShuIcof {

    class TreeNode {

        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public boolean isSymmetric(TreeNode root) {
        return com(root, root);
    }


    public boolean com(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        } else if (left == null) {
            return false;
        } else if (right == null) {
            return false;
        }

        if(left.val==right.val){
            return com(left.left, right.right) && com(left.right, right.left);
        }else {
            return false;
        }


    }

    public boolean compare2(TreeNode left, TreeNode right){
        if(left==null&&right==null){
            return true;
        }
        if(left==null||right==null){
            return false;
        }
        return left==right&&compare2(left.left,right.right)&&compare2(left.right,right.left);
    }

    @Test
    public void test() {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(2);
        root.left.left = new TreeNode(3);
        root.left.right = new TreeNode(4);
        root.right.right = new TreeNode(3);
        root.right.left = new TreeNode(4);

        System.out.println(isSymmetric(null));
    }


}
    